<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">


<ui:composition template="/layout/mobileLayout.xhtml">
	<ui:define name="contentPart">

		<h:form id="formClients" style="font-size:40px;"> 
			<script type="text/javascript">
				function handleMessage(facesmessage) {	
					window.location = location.href;
					#{mobileAction.load}
				}
			</script>

			<p:socket onMessage="handleMessage" channel="/notificationsChannel" />
		
			<p:panel id="rpnl" header="Source file(s)">
				<h:outputText id="fileValue" value="#{mobileAction.treeBean.selectedNode.label}" />
			</p:panel>

			<h:panelGrid id="clientsPG"
				rendered="#{!(fn:length(mobileAction.clientDBs) eq 0)}">
				<ui:repeat id="repeater" value="#{mobileAction.clientDBs}" var="db"
					varStatus="status">
					<h:panelGrid columns="1" id="clientPG">
						<h:panelGrid columns="1" style="text-align:center">
							<h:outputText value="#{db.name}"
								style="font-size:44px;color:black;font-weight:bold" />
						</h:panelGrid>

						<h:panelGrid columns="7">
							<p:commandButton styleClass="buttonTable128" icon="buttonPlay128"
								action="#{mobileAction.streamFile}" update=":growl"
								style="width:100%" title="Start to stream selected file(s)">
								<f:setPropertyActionListener
									target="#{mobileAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable128"
								icon="buttonPause128" action="#{mobileAction.suspendStream}"
								update=":growl :formClients:clientsPG" style="width:100%"
								rendered="#{!(db.resumeVisible)}" title="Suspend current stream">
								<f:setPropertyActionListener
									target="#{mobileAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable128"
								icon="buttonResume128" title="Resume current stream"
								action="#{mobileAction.resumeStream}"
								update=":formClients:clientsPG" style="width:100%"
								rendered="#{(db.resumeVisible)}">
								<f:setPropertyActionListener
									target="#{mobileAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable128"
								icon="buttonPrevious128" action="#{mobileAction.playPrevious}"
								update=":growl" style="width:100%" title="Stream previous file">
								<f:setPropertyActionListener
									target="#{mobileAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable128" icon="buttonNext128"
								action="#{mobileAction.playNext}" update=":growl"
								style="width:100%" title="Stream next file">
								<f:setPropertyActionListener
									target="#{mobileAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable128" icon="buttonStop128"
								action="#{mobileAction.stopStream}" update=":growl"
								style="width:100%">
								<f:setPropertyActionListener
									target="#{mobileAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>

							<p:commandButton styleClass="buttonTable128"
								icon="buttonShuffleOn128" action="#{mobileAction.shuffleStream}"
								update=":growl :formClients:clientsPG" style="width:100%"
								rendered="#{!(db.client.srv.shuffle)}" title="Shuffle mode on">
								<f:setPropertyActionListener
									target="#{mobileAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable128"
								icon="buttonShuffleOff128"
								action="#{mobileAction.shuffleStream}"
								update=":growl :formClients:clientsPG" style="width:100%"
								rendered="#{(db.client.srv.shuffle)}" title="Shuffle mode off">
								<f:setPropertyActionListener
									target="#{mobileAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							
							<p:commandButton action="#{mobileAction.addToPlayList}" 
								icon="buttonAdd128" styleClass="buttonTable128"
								update=":growl :formClients:clientsPG" style="width:100%"
								title="Add to play list">
								<f:setPropertyActionListener
									target="#{mobileAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
						</h:panelGrid>
						<h:outputText value="#{db.client.currentFilePath}" />
					</h:panelGrid>
				</ui:repeat>
			</h:panelGrid>
		</h:form>
		
		<h:form id="formTree" style="font-size:40px;">
				
			<p:tree value="#{treeBean.root}" var="node" id="tree"
				widgetVar="tree" selectionMode="single"
				selection="#{treeBean.selectedNode}" style="width:100%;border:0">

				<p:ajax event="select" update=":formTree :formClients"
					listener="#{treeBean.onNodeSelect}" />

				<p:treeNode id="treeNode">
					<h:outputText value="#{node}" id="lblNode" />
				</p:treeNode>
			</p:tree>

		</h:form>
	</ui:define>
</ui:composition>
</html>